package gold.digger;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC690 {
    public long startExecuteTime = System.currentTimeMillis();

    // Definition for Employee.
    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    class Solution {

        public int getImportance(List<Employee> employees, int id) {
            Map<Integer, Employee> dict = new HashMap<>();
            for (Employee employee : employees) {
                dict.put(employee.id, employee);
            }

            Deque<Employee> queue = new LinkedList<>();
            queue.offerLast(dict.get(id));
            int totalImportance = 0;

            while (!queue.isEmpty()) {
                int size = queue.size();
                for (int i = 0; i < size; i++) {
                    Employee cur = queue.pollFirst();
                    totalImportance += cur.importance;
                    for (Integer subordinate : cur.subordinates) {
                        queue.offerLast(dict.get(subordinate));
                    }
                }
            }

            return totalImportance;
        }
    }

    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC690 an = new LC690();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
